home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / exampleCode / opengl / GLUT / test / test2.c < prev    next >
C/C++ Source or Header  |  1996-11-11  |  4KB  |  165 lines

  1.  
  2. /* Copyright (c) Mark J. Kilgard, 1994, 1996. */
  3.  
  4. /* This program is freely distributable without licensing fees 
  5.    and is provided without guarantee or warrantee expressed or 
  6.    implied. This program is -not- in the public domain. */
  7.  
  8. #ifdef __sgi
  9. #include <malloc.h>
  10. #endif
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include <GL/glut.h>
  14. #include <glutint.h>
  15.  
  16. int count = 0, save_count;
  17. int start, end, diff;
  18.  
  19. void
  20. idle(void)
  21. {
  22.   count++;
  23. }
  24.  
  25. void
  26. timer2(int value)
  27. {
  28.   if (value != 36)
  29.     __glutFatalError("FAIL: timer value wrong");
  30.   if (count != save_count)
  31.     __glutFatalError("FAIL: counter still counting");
  32.   printf("PASS: test2\n");
  33.   exit(0);
  34. }
  35.  
  36. void
  37. timer(int value)
  38. {
  39.   if (value != 42)
  40.     __glutFatalError("FAIL: timer value wrong");
  41.   if (count <= 0)
  42.     __glutFatalError("FAIL: idle func not running");
  43.   glutIdleFunc(NULL);
  44.   save_count = count;
  45.   end = glutGet(GLUT_ELAPSED_TIME);
  46.   diff = end - start;
  47.   printf("diff = %d (%d - %d)\n", diff, end, start);
  48.   if (diff > ((int) 500 * 1.2)) {
  49.     __glutFatalError("FAIL: timer too late");
  50.   }
  51.   if (diff < ((int) 500 * .9)) {
  52.     __glutFatalError("FAIL: timer too soon");
  53.   }
  54.   glutTimerFunc(100, timer2, 36);
  55. }
  56.  
  57. void
  58. menuSelect(int value)
  59. {
  60. }
  61.  
  62. void
  63. NeverVoid(void)
  64. {
  65.   __glutFatalError("FAIL: NeverVoid should never be called");
  66. }
  67.  
  68. void
  69. NeverValue(int value)
  70. {
  71.   __glutFatalError("FAIL: NeverValue should never be called");
  72. }
  73.  
  74. #define NUM 15
  75.  
  76. void
  77. display(void)
  78. {
  79.   glClear(GL_COLOR_BUFFER_BIT);
  80. }
  81.  
  82. int
  83. main(int argc, char **argv)
  84. {
  85.   int win, menu;
  86.   int marray[NUM];
  87.   int warray[NUM];
  88.   int i, j;
  89.   GLint isIndex;
  90.  
  91. #if defined(__sgi)  && !defined(REDWOOD)
  92.   /* XXX IRIX 6.0.1 mallopt(M_DEBUG, 1) busted. */
  93.   mallopt(M_DEBUG, 1);
  94. #endif
  95.   glutInit(&argc, argv);
  96.   glutInitWindowPosition(10, 10);
  97.   glutInitWindowSize(200, 200);
  98.   glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
  99.   win = glutCreateWindow("test2");
  100.   glGetIntegerv(GL_INDEX_MODE, &isIndex);
  101.   if (isIndex != 0) {
  102.     __glutFatalError("FAIL: window should be RGBA");
  103.   }
  104.   glutSetWindow(win);
  105.   glutDisplayFunc(display);
  106.   menu = glutCreateMenu(menuSelect);
  107.   glutSetMenu(menu);
  108.   glutReshapeFunc(NULL);
  109.   glutReshapeFunc(NULL);
  110.   glutKeyboardFunc(NULL);
  111.   glutKeyboardFunc(NULL);
  112.   glutMouseFunc(NULL);
  113.   glutMouseFunc(NULL);
  114.   glutMotionFunc(NULL);
  115.   glutMotionFunc(NULL);
  116.   glutVisibilityFunc(NULL);
  117.   glutVisibilityFunc(NULL);
  118.   glutMenuStateFunc(NULL);
  119.   glutMenuStateFunc(NULL);
  120.   glutMenuStatusFunc(NULL);
  121.   glutMenuStatusFunc(NULL);
  122.   glutSpecialFunc(NULL);
  123.   glutSpecialFunc(NULL);
  124.   glutSpaceballMotionFunc(NULL);
  125.   glutSpaceballMotionFunc(NULL);
  126.   glutSpaceballRotateFunc(NULL);
  127.   glutSpaceballRotateFunc(NULL);
  128.   glutSpaceballButtonFunc(NULL);
  129.   glutSpaceballButtonFunc(NULL);
  130.   glutButtonBoxFunc(NULL);
  131.   glutButtonBoxFunc(NULL);
  132.   glutDialsFunc(NULL);
  133.   glutDialsFunc(NULL);
  134.   glutTabletMotionFunc(NULL);
  135.   glutTabletMotionFunc(NULL);
  136.   glutTabletButtonFunc(NULL);
  137.   glutTabletButtonFunc(NULL);
  138.   for (i = 0; i < NUM; i++) {
  139.     marray[i] = glutCreateMenu(menuSelect);
  140.     warray[i] = glutCreateWindow("test");
  141.     glutDisplayFunc(display);
  142.     for (j = 0; j < i; j++) {
  143.       glutAddMenuEntry("Hello", 1);
  144.       glutAddSubMenu("Submenu", menu);
  145.     }
  146.     if (marray[i] != glutGetMenu()) {
  147.       __glutFatalError("FAIL: current menu not %d", marray[i]);
  148.     }
  149.     if (warray[i] != glutGetWindow()) {
  150.       __glutFatalError("FAIL: current window not %d", warray[i]);
  151.     }
  152.     glutDisplayFunc(NeverVoid);
  153.     glutVisibilityFunc(NeverValue);
  154.   }
  155.   for (i = 0; i < NUM; i++) {
  156.     glutDestroyMenu(marray[i]);
  157.     glutDestroyWindow(warray[i]);
  158.   }
  159.   glutTimerFunc(500, timer, 42);
  160.   start = glutGet(GLUT_ELAPSED_TIME);
  161.   glutIdleFunc(idle);
  162.   glutMainLoop();
  163.   return 0;             /* ANSI C requires main to return int. */
  164. }
  165.